#include <bits/stdc++.h>

using namespace std;
#define fi(i, init, n) for (int i = init; i < n; i++)   // i为循环变量，a为初始值，n为界限值，递增
#define rfi(i, init, n) for (int i = init; i > n; i--)  // i为循环变量， a为初始值，n为界限值，递减。
#define vi vector<int>
#define mii unordered_map<int, int>
#define between(a, l, h) (a >= l && a <= h)
const int INF = 0x7fffffff;  // 无穷大
typedef long long ll;

class Solution {
public:
    ll numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {
        mii factor;
        for (int n : nums1) {
            for (int j = 1; j * j <= n; j++) {
                if (n % j == 0) {
                    factor[n / j]++;
                    if (n / j != j) factor[j]++;
                }
            }
        }

        ll ans = 0;
        for (auto n2 : nums2) {
            ans += factor[n2 * k];
        }
        return ans;
    }
};

int main() {
    Solution solution = Solution();
    vector<int> in = {1, 24};
    vector<int> in2 = {12, 3, 6};
    auto res = solution.numberOfPairs(in, in2, 8);
    cout << res << endl;
    return 0;
}